﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using BussinessLayer;

namespace projectQLDV
{
    public partial class frmCaiDatChucVu : DevExpress.XtraEditors.XtraForm
    {
        private int id;
        private string tendv;
        private frmMain frmM;
        public frmCaiDatChucVu(frmMain frm, int _id, string _name)
        {
            InitializeComponent();
            id = _id;
            tendv = _name;
            frmM = frm;
        }

        private void loadChucVu(string _namhoc)
        {
            tblChucvu cv = new tblChucvu();
            DataTable dt = new DataTable();
            DataTable dvcv =  new DataTable();
            dt = cv.SelectChucvu();
            dvcv = cv.SelectCVof(this.id, _namhoc);
            string[][] acv = new string[dt.Rows.Count][];
            int dem = 0;
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                acv[i] = new string[]{"false", dt.Rows[i]["chucvu_id"].ToString(), dt.Rows[i]["chucvu_ten"].ToString()};
                dem++;
            }
            for(int i = 0; i < dem; i++)
            {
                for (int j = 0; j < dvcv.Rows.Count; j++)
                {
                    if (dvcv.Rows[j]["chucvu_id"].ToString().Trim().Equals(acv[i][1]))
                        acv[i][0] = "true";
                }
                if (acv[i][0] == "true")
                    this.checkedListBoxChucVu.Items.Add(acv[i][1], acv[i][2], CheckState.Checked, true);
                else this.checkedListBoxChucVu.Items.Add(acv[i][1], acv[i][2], CheckState.Unchecked, false);
            }
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            this.Close();
            this.Dispose();
        }

        private void btnLuuVaThoat_Click(object sender, EventArgs e)
        {

        }

        private void btnLuu_Click(object sender, EventArgs e)
        {

        }

        private void comboBoxNamdoanvien_SelectedIndexChanged(object sender, EventArgs e)
        {
            loadChucVu(this.comboBoxNamdoanvien.Text);
        }
    }
}